from datetime import datetime
import pandas as pd
from pathlib import Path
import plotly
import plotly.express as px
import numpy as np
from statsmodels.tsa.api import VAR
import urllib.request
plotly.offline.init_notebook_mode()
NOW = datetime.now()
TODAY = NOW.date()
print('Aktualisiert:', NOW)
Aktualisiert: 2022-10-19 14:15:10.762590
STATE_NAMES = ['Burgenland', 'Kärnten', 'Niederösterreich',
'Oberösterreich', 'Salzburg', 'Steiermark',
'Tirol', 'Vorarlberg', 'Wien']
# TODO: Genauer recherchieren!
EVENTS = {'1. Lockdown': (np.datetime64('2020-03-20'), np.datetime64('2020-04-14'),
'red', 'inside top left'),
'1. Maskenpflicht': (np.datetime64('2020-03-30'), np.datetime64('2020-06-15'),
'yellow', 'inside bottom left'),
'2. Maskenpflicht': (np.datetime64('2020-07-24'), np.datetime64(TODAY),
'yellow', 'inside bottom left'),
'1. Soft Lockdown': (np.datetime64('2020-11-03'), np.datetime64('2020-11-17'),
'orange', 'inside top left'),
'2. Lockdown': (np.datetime64('2020-11-17'), np.datetime64('2020-12-06'),
'red', 'inside top left'),
'2. Soft Lockdown': (np.datetime64('2020-12-06'), np.datetime64('2020-12-27'),
'orange', 'inside top left'),
'Weihnachten 2020': (np.datetime64('2020-12-24'), np.datetime64('2020-12-27'),
'blue', 'inside top left'),
'3. Lockdown': (np.datetime64('2020-12-27'), np.datetime64(TODAY),
'red', 'inside top left')}
def load_data(URL, date_columns):
data_file = Path(URL).name
try:
# Only download the data if we don't have it, to avoid
# excessive server access during local development
with open(data_file):
print("Using local", data_file)
except FileNotFoundError:
print("Downloading", URL)
urllib.request.urlretrieve(URL, data_file)
return pd.read_csv(data_file, sep=';', parse_dates=date_columns, infer_datetime_format=True, dayfirst=True)
raw_data = load_data("https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv", [0])
additional_data = load_data("https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv", [0, 2])
Downloading https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv Downloading https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv
cases = raw_data.query("Bundesland == 'Österreich'")
cases.insert(0, 'AnzahlFaelle_avg7', cases.AnzahlFaelle7Tage / 7)
time = cases.Time
tests = additional_data.query("Bundesland == 'Alle'")
tests.insert(2, 'TagesTests', np.concatenate([[np.nan], np.diff(tests.TestGesamt)]))
tests.insert(3, 'TagesTests_avg7', np.concatenate([[np.nan] * 7, (tests.TestGesamt.values[7:] - tests.TestGesamt.values[:-7])/7]))
tests.insert(0, 'Time', tests.MeldeDatum)
fig = px.line(cases, x='Time', y=["AnzahlFaelle", "AnzahlFaelle_avg7"], log_y=True, title="Fallzahlen")
fig.add_scatter(x=tests.Time, y=tests.TagesTests, name='Tests')
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
all_data = tests.merge(cases, on='Time', how='outer')
all_data.insert(1, 'PosRate', all_data.AnzahlFaelle / all_data.TagesTests)
all_data.insert(1, 'PosRate_avg7', all_data.AnzahlFaelle_avg7 / all_data.TagesTests_avg7)
fig = px.line(all_data, x='Time', y=['PosRate', 'PosRate_avg7'], log_y=False, title="Anteil Positiver Tests")
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
states = []
rates = []
for state_name, state_data in raw_data.groupby('Bundesland'):
x = np.log2(state_data.AnzahlFaelle7Tage)
rate = 2**np.array(np.diff(x))
rates.append(rate)
states.append(state_name)
growth = pd.DataFrame({n: r for n, r in zip(states, rates)})
fig = px.line(growth, x=time[1:], y=STATE_NAMES, title='Wachstumsrate')
fig.update_layout(yaxis=dict(range=[0.25, 4]))
fig.show()
/usr/share/miniconda/lib/python3.8/site-packages/pandas/core/series.py:726: RuntimeWarning: divide by zero encountered in log2 /usr/share/miniconda/lib/python3.8/site-packages/numpy/lib/function_base.py:1280: RuntimeWarning: invalid value encountered in subtract
model = VAR(growth[150:][STATE_NAMES])
res = model.fit(1)
res.summary()
Summary of Regression Results
==================================
Model: VAR
Method: OLS
Date: Wed, 19, Oct, 2022
Time: 14:15:17
--------------------------------------------------------------------
No. of Equations: 9.00000 BIC: -50.7556
Nobs: 814.000 HQIC: -51.0759
Log likelihood: 10564.0 FPE: 5.38706e-23
AIC: -51.2755 Det(Omega_mle): 4.82644e-23
--------------------------------------------------------------------
Results for equation Burgenland
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.295238 0.052367 5.638 0.000
L1.Burgenland 0.108921 0.035288 3.087 0.002
L1.Kärnten -0.106378 0.018793 -5.661 0.000
L1.Niederösterreich 0.210465 0.073804 2.852 0.004
L1.Oberösterreich 0.100972 0.070779 1.427 0.154
L1.Salzburg 0.250068 0.037563 6.657 0.000
L1.Steiermark 0.037791 0.049206 0.768 0.442
L1.Tirol 0.106297 0.039904 2.664 0.008
L1.Vorarlberg -0.058701 0.034317 -1.711 0.087
L1.Wien 0.059787 0.063129 0.947 0.344
======================================================================================
Results for equation Kärnten
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.061671 0.108368 0.569 0.569
L1.Burgenland -0.033386 0.073024 -0.457 0.648
L1.Kärnten 0.047814 0.038889 1.229 0.219
L1.Niederösterreich -0.171735 0.152729 -1.124 0.261
L1.Oberösterreich 0.385631 0.146468 2.633 0.008
L1.Salzburg 0.286714 0.077732 3.688 0.000
L1.Steiermark 0.105163 0.101825 1.033 0.302
L1.Tirol 0.314053 0.082577 3.803 0.000
L1.Vorarlberg 0.025454 0.071016 0.358 0.720
L1.Wien -0.014875 0.130638 -0.114 0.909
======================================================================================
Results for equation Niederösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.189019 0.026883 7.031 0.000
L1.Burgenland 0.090381 0.018115 4.989 0.000
L1.Kärnten -0.008406 0.009647 -0.871 0.384
L1.Niederösterreich 0.264974 0.037887 6.994 0.000
L1.Oberösterreich 0.126196 0.036334 3.473 0.001
L1.Salzburg 0.048224 0.019283 2.501 0.012
L1.Steiermark 0.016894 0.025259 0.669 0.504
L1.Tirol 0.094688 0.020485 4.622 0.000
L1.Vorarlberg 0.059321 0.017617 3.367 0.001
L1.Wien 0.119689 0.032407 3.693 0.000
======================================================================================
Results for equation Oberösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.109131 0.027546 3.962 0.000
L1.Burgenland 0.044512 0.018562 2.398 0.016
L1.Kärnten -0.016100 0.009885 -1.629 0.103
L1.Niederösterreich 0.193387 0.038821 4.981 0.000
L1.Oberösterreich 0.293439 0.037230 7.882 0.000
L1.Salzburg 0.115824 0.019758 5.862 0.000
L1.Steiermark 0.099711 0.025882 3.852 0.000
L1.Tirol 0.116716 0.020990 5.561 0.000
L1.Vorarlberg 0.070573 0.018051 3.910 0.000
L1.Wien -0.027639 0.033206 -0.832 0.405
======================================================================================
Results for equation Salzburg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.124520 0.050051 2.488 0.013
L1.Burgenland -0.051134 0.033727 -1.516 0.129
L1.Kärnten -0.040348 0.017961 -2.246 0.025
L1.Niederösterreich 0.170901 0.070539 2.423 0.015
L1.Oberösterreich 0.137431 0.067648 2.032 0.042
L1.Salzburg 0.285443 0.035901 7.951 0.000
L1.Steiermark 0.033330 0.047029 0.709 0.478
L1.Tirol 0.165735 0.038139 4.346 0.000
L1.Vorarlberg 0.104320 0.032799 3.181 0.001
L1.Wien 0.071768 0.060337 1.189 0.234
======================================================================================
Results for equation Steiermark
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.059913 0.039616 1.512 0.130
L1.Burgenland 0.038977 0.026695 1.460 0.144
L1.Kärnten 0.050804 0.014217 3.574 0.000
L1.Niederösterreich 0.225891 0.055833 4.046 0.000
L1.Oberösterreich 0.282178 0.053544 5.270 0.000
L1.Salzburg 0.051620 0.028416 1.817 0.069
L1.Steiermark -0.007906 0.037224 -0.212 0.832
L1.Tirol 0.149756 0.030188 4.961 0.000
L1.Vorarlberg 0.070878 0.025961 2.730 0.006
L1.Wien 0.078828 0.047757 1.651 0.099
======================================================================================
Results for equation Tirol
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.175422 0.047365 3.704 0.000
L1.Burgenland -0.005560 0.031917 -0.174 0.862
L1.Kärnten -0.061113 0.016998 -3.595 0.000
L1.Niederösterreich -0.083025 0.066754 -1.244 0.214
L1.Oberösterreich 0.192402 0.064018 3.005 0.003
L1.Salzburg 0.057493 0.033975 1.692 0.091
L1.Steiermark 0.229616 0.044505 5.159 0.000
L1.Tirol 0.494851 0.036092 13.711 0.000
L1.Vorarlberg 0.049696 0.031039 1.601 0.109
L1.Wien -0.047713 0.057099 -0.836 0.403
======================================================================================
Results for equation Vorarlberg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.161314 0.054347 2.968 0.003
L1.Burgenland -0.011107 0.036622 -0.303 0.762
L1.Kärnten 0.065953 0.019503 3.382 0.001
L1.Niederösterreich 0.200941 0.076594 2.623 0.009
L1.Oberösterreich -0.061511 0.073454 -0.837 0.402
L1.Salzburg 0.216998 0.038983 5.566 0.000
L1.Steiermark 0.113491 0.051066 2.222 0.026
L1.Tirol 0.077632 0.041413 1.875 0.061
L1.Vorarlberg 0.124493 0.035615 3.496 0.000
L1.Wien 0.113782 0.065515 1.737 0.082
======================================================================================
Results for equation Wien
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.352681 0.031681 11.132 0.000
L1.Burgenland 0.006017 0.021348 0.282 0.778
L1.Kärnten -0.023585 0.011369 -2.075 0.038
L1.Niederösterreich 0.224486 0.044650 5.028 0.000
L1.Oberösterreich 0.174382 0.042820 4.072 0.000
L1.Salzburg 0.048106 0.022725 2.117 0.034
L1.Steiermark -0.016559 0.029768 -0.556 0.578
L1.Tirol 0.109415 0.024141 4.532 0.000
L1.Vorarlberg 0.073635 0.020761 3.547 0.000
L1.Wien 0.052594 0.038192 1.377 0.168
======================================================================================
Correlation matrix of residuals
Burgenland Kärnten Niederösterreich Oberösterreich Salzburg Steiermark Tirol Vorarlberg Wien
Burgenland 1.000000 0.041569 0.152752 0.189692 0.158292 0.124518 0.114565 0.065612 0.226508
Kärnten 0.041569 1.000000 -0.002306 0.129849 0.042194 0.096119 0.429707 -0.052938 0.101225
Niederösterreich 0.152752 -0.002306 1.000000 0.337203 0.155511 0.300700 0.111895 0.184151 0.328311
Oberösterreich 0.189692 0.129849 0.337203 1.000000 0.232419 0.332719 0.172968 0.172813 0.263264
Salzburg 0.158292 0.042194 0.155511 0.232419 1.000000 0.146577 0.128864 0.149401 0.134717
Steiermark 0.124518 0.096119 0.300700 0.332719 0.146577 1.000000 0.153864 0.141167 0.079285
Tirol 0.114565 0.429707 0.111895 0.172968 0.128864 0.153864 1.000000 0.115397 0.155269
Vorarlberg 0.065612 -0.052938 0.184151 0.172813 0.149401 0.141167 0.115397 1.000000 0.007595
Wien 0.226508 0.101225 0.328311 0.263264 0.134717 0.079285 0.155269 0.007595 1.000000